package com.ruoyi.crm.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.MongoLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.Clue;
import com.ruoyi.crm.domain.vo.ClueTrackVo;
import com.ruoyi.crm.domain.vo.FalseClueVo;
import com.ruoyi.crm.domain.vo.TransformVo;
import com.ruoyi.crm.service.IClueService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/crm/clueTrack")
public class ClueTrackController extends BaseController {

    @Resource
    private IClueService clueService;

//    @Log(title = "线索跟踪记录")
@MongoLog(tableName = MongoLog.TableName.ClUE,title = "线索跟踪记录",businessType = BusinessType.INSERT )
@PostMapping
    public AjaxResult add(@RequestBody ClueTrackVo clueTrackVo){
        clueTrackVo.setStatus(Clue.Status.TRACKING.getValue());
       return toAjax(clueService.updateClue(clueTrackVo));
    }


    /**
     * 线索上报
     * @param falseClueVo
     * @return
     */
    @Log(title = "线索跟踪记录")
    @PutMapping
    public AjaxResult falseClue(@RequestBody FalseClueVo falseClueVo){

        return toAjax(clueService.falseClue(falseClueVo.getId()));
    }

    /**
     * 转商机
     * @param transformVo
     * @return
     */
    @Log(title = "线索跟踪记录")
    @PutMapping("/transform")
    public AjaxResult transform(@RequestBody TransformVo transformVo){

        return toAjax(clueService.transformToBusiness(transformVo.getId()));
    }

    /**
     * ；捞取
     * @param transformVo
     * @return
     */
    @Log(title = "线索跟踪记录")
    @PutMapping("/resetClue")
    public AjaxResult resetClue(@RequestBody TransformVo transformVo){
        return toAjax(clueService.resetClue(transformVo.getId()));
    }
}
